<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>条件运算符</title>
</head>

<!-- 比较和逻辑运算符用于测试 true 或者 false。 -->

<body>
    <p>点击按钮检测年龄。</p>
    年龄:<input id="age" value="18" />
    <p>是否达到投票年龄?</p>
    <button onclick="myFunction()">点击按钮</button>
    <p id="demo"></p>
    <script>
        function myFunction() {
            var age, voteable;
            age = document.getElementById("age").value;
            voteable = (age < 18) ? "年龄太小" : "年龄已达到";
            document.getElementById("demo").innerHTML = voteable;
        }
    </script>
</body>

</html>